IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MachineDriveVolumeSpace]') AND type in (N'U'))
BEGIN
     DROP TABLE [dbo].[MachineDriveVolumeSpace]
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[MachineDriveVolumeSpace](
     [MachineId]                   [int]      NOT NULL,
     [MachineDriveVolumeId]        [int]      NOT NULL,
     [CaptureDt]                   [datetime] NOT NULL,
     [PackageExecutionId]          [bigint]   NOT NULL,
     [VolumeCapacityBytes]         [bigint]   NOT NULL,
     [VolumeFreeSpaceBytes]        [bigint]   NOT NULL,
     [VolumeUsedSpaceBytes]  AS ([VolumeCapacityBytes]-[VolumeFreeSpaceBytes]) PERSISTED,
     [VolumeCapacityKBytes]  AS ([VolumeCapacityBytes]/(1024)) PERSISTED,
     [VolumeFreeSpaceKBytes]  AS ([VolumeFreeSpaceBytes]/(1024)) PERSISTED,
     [VolumeUsedSpaceKBytes]  AS (([VolumeCapacityBytes]-[VolumeFreeSpaceBytes])/(1024)) PERSISTED,
     [VolumeFreeSpacePCT]  AS (CONVERT([decimal](7,4),(CONVERT([decimal](38,5),[VolumeFreeSpaceBytes],0)/CONVERT([decimal](38,5),[VolumeCapacityBytes],0))*(100),0)) PERSISTED,
     [VolumeUsedSpacePCT]  AS (CONVERT([decimal](7,4),(CONVERT([decimal](38,5),[VolumeCapacityBytes]-[VolumeFreeSpaceBytes],0)/CONVERT([decimal](38,5),[VolumeCapacityBytes],0))*(100),0)) PERSISTED
     [FreeSpaceOutsideTolerance]   [tinyint]      NULL,
     [FreeSpaceAlertGeneratedFlag] [tinyint]      NULL,
     CONSTRAINT [PK_MachineDriveVolumeSpace] PRIMARY KEY CLUSTERED ( [MachineId] ASC, [MachineDriveVolumeId] ASC, [CaptureDt] ASC )
) ON [PRIMARY]
GO

SET ANSI_PADDING OFF
GO
